package jiaxa.com.list;

import android.database.DataSetObserver;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    //    private LinearLayout llContainer;
    //    private Button btnList;
    private ListView lvList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);


        //        llContainer = (LinearLayout) findViewById(R.id.llContainer);
        //        btnList = (Button) findViewById(R.id.btnList);
        //
        //        btnList.setOnClickListener(new View.OnClickListener() {
        //            @Override
        //            public void onClick(View v) {
        //                for (int i=0;i<10;i++){
        //                    TextView tv=new TextView(MainActivity.this);
        //                    tv.setText("我是文本："+i);
        //                    tv.setTextColor(Color.RED);
        //                    tv.setTextSize(20);
        //                    llContainer.addView(tv);
        //                }
        //            }
        //        });


        lvList = (ListView) findViewById(R.id.lvList);
        lvList.setAdapter(new lvListAdapter());
    }

    private class lvListAdapter implements ListAdapter {
        @Override
        public boolean areAllItemsEnabled() {
            return false;
        }

        @Override
        public boolean isEnabled(int position) {
            return false;
        }

        @Override
        public void registerDataSetObserver(DataSetObserver observer) {

        }

        @Override
        public void unregisterDataSetObserver(DataSetObserver observer) {

        }

        @Override
        public int getCount() {
            return 1000;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            TextView tv = null;
            if (convertView == null) {
                tv = new TextView(MainActivity.this);
            } else {
                tv = (TextView) convertView;
            }
            tv.setText("我是文本：" + position);
            tv.setTextColor(Color.RED);
            tv.setTextSize(20);
            return tv;
        }

        @Override
        public int getItemViewType(int position) {
            return 0;
        }

        @Override
        public int getViewTypeCount() {
            return 0;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    }
}
